package com.xiaocai.objview.display;

import android.content.Context;
import android.opengl.GLES20;

import com.xiaocai.objview.R;
import com.xiaocai.objview.gl.ShaderProgram;
import com.xiaocai.objview.gl.TextureHelper;

public class ObjViewShaderProgram extends ShaderProgram {

    private final String A_POSITION = "a_Position";

    private final String A_COLOR = "a_Color";

    private final String U_MATRIX = "u_Matrix";

    private final String A_COORD = "a_Coord";

    private int aPositionLocation;

    private int aColorLocation;

    private int uMatrixLocation;

    private int aCoordLocation;

    private int u_SamplerLocation;

    private int textureId;

    public ObjViewShaderProgram(Context context) {
        super(context, R.raw.obj_vertex_shader, R.raw.obj_fragment_shader);

        textureId = TextureHelper.loadTexture();

        aPositionLocation = GLES20.glGetAttribLocation(program, A_POSITION);
        aColorLocation = GLES20.glGetAttribLocation(program, A_COLOR);
        uMatrixLocation = GLES20.glGetUniformLocation(program, U_MATRIX);
        aCoordLocation = GLES20.glGetAttribLocation(program, A_COORD);
        u_SamplerLocation = GLES20.glGetUniformLocation(program, "u_Sampler");
    }

    public void setUniforms(float[] matrix) {
        GLES20.glUniformMatrix4fv(uMatrixLocation, 1, false, matrix, 0);
    }

    public int getTextureId() {
        return textureId;
    }

    public int getPositionLocation() {
        return aPositionLocation;
    }

    public int getColorLocation() {
        return aColorLocation;
    }

    public int getCoordLocation() {
        return aCoordLocation;
    }

    public int getU_SamplerLocation() {
        return u_SamplerLocation;
    }
}
